package com.redlion.weapon;

import java.util.ArrayList;

import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.ITiledTextureRegion;

public class WeaponEntry {
	public ITiledTextureRegion mTiledTextureRegion;
	public String name;
	public int weaponIndex;
	public int[] textureIndices;

	public ArrayList<Upgrade> upgrades = new ArrayList<Upgrade>();
	public int mTileIndex;
	public OnFireListener fireListener;

	public WeaponEntry(String name, int index) {
		this.weaponIndex = index;
		this.name = name;
	}

	public boolean hasAnimation() {
		return mTiledTextureRegion != null;
	}

	public void addUpgrade(float delay, float damage, int price) {
		Upgrade u = new Upgrade(delay, damage, price);
		u.index = upgrades.size();
		if (!contains(u))
			upgrades.add(u);
	}

	public void addUpgrade(Upgrade u) {
		u.index = upgrades.size();
		if (!contains(u))
			upgrades.add(u);
	}

	public boolean contains(Upgrade u) {
		for (Upgrade uList : upgrades) {
			if (u.identical(uList))
				return true;
		}
		return false;
	}

	public boolean hasNext(int i) {
		return upgrades.size() > (i + 1);
	}

	public Upgrade next(int index) {
		if (hasNext(index))
			return upgrades.get(index + 1);
		return null;
	}

	public Upgrade upgrade(short currentIndex) {
		if (hasNext(currentIndex)) {
			return upgrades.get(currentIndex + 1);
		}
		return null;
	}

	public void clear() {
		upgrades.clear();
	}

	public Upgrade getUpgrade(int index) {
		if (upgrades.size() > index)
			return upgrades.get(index);
		return null;
	}

	public ArrayList<Upgrade> getUpgrades() {
		return upgrades;
	}

	public OnFireListener getFireListener() {
		return fireListener;
	}

	public void setOnFireListener(OnFireListener iFireListener) {
		fireListener = iFireListener;
	}
}
